﻿package sch.jl.caigou.utils;

import java.util.List;

public class Page<T> {

	//当前第几页
	private int pageNo;
	//当前页List
	private List<T> list;
	//每页显示多少条记录
	private int pageSize = 10;
	//共多少条记录
	private int totalItemNumber;
	
	
	public Page() {
		super();
	}
	public Page(int pageNo)
	{
		super();
		this.pageNo=pageNo;
	}
	public int getPageNo()
	{
		if(pageNo<0)
		{
			pageNo=1;
		}
		else if(pageNo>getTotalPageNumber())
		{
			pageNo=getTotalPageNumber();
		}
		return pageNo;
	}
	public int getTotalPageNumber()
	{
		int totalPageNumber = (int)totalItemNumber/pageSize;
		if(totalItemNumber % pageSize !=0)
		{
			totalPageNumber++;
		}
		return totalPageNumber;
		
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalItemNumber() {
		return totalItemNumber;
	}
	public void setTotalItemNumber(int totalItemNumber) {
		this.totalItemNumber = totalItemNumber;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	
	public boolean isHasPrev()
	{
		if(getPageNo()<2)
			return false;
		return true;
	}
	public boolean isHasNext()
	{
		if(getPageNo()<getTotalPageNumber())
			return true;
		return false;
	}
	public int getPrevPage()
	{
		if(isHasPrev())
		{
			return getPageNo()-1;
		}
		return getPageNo();
	}
	public int getNextPage()
	{
		if(isHasNext())
		{
			return getPageNo()+1;
		}
		return getPageNo();
	}
	
}
